package com.barras;

import org.achartengine.ChartFactory;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.TimeSeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;

public class classLine
{
	public XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
	public XYMultipleSeriesRenderer mRender = new XYMultipleSeriesRenderer();
		
	public Intent getIntent (Context context)
	{
		int [] x = {1,2,3,4,5,6,7,8,9,10};
		int [] y = {4,6,3,7,8,1,3,5,7,8};
		
		int [] x2 = {1,2,3,4,5,6,7,8,9,10};
		int [] y2 = {14,16,13,9,7,1,13,15,17,18};
		
		TimeSeries series = new TimeSeries("Line 1");
		for (int i= 0; i < x.length; i++)
		{
			series.add(x[i],y[i]);
		}
		
		TimeSeries series2 = new TimeSeries("Line 2");
		for (int i= 0; i < x2.length; i++)
		{
			series2.add(x2[i],y2[i]);
		}
			
		dataset.addSeries(series);
		dataset.addSeries(series2);
		
		//##########################################
		//MOFICAR CADA LINEA
		XYSeriesRenderer render = new XYSeriesRenderer();
		XYSeriesRenderer render2 = new XYSeriesRenderer();
		
		render.setChartValuesTextSize(15);
		render.setLineWidth(5);
		render.setChartValuesSpacing(10);
		render.setDisplayChartValues(true);
		render.setPointStyle(PointStyle.SQUARE);
		render.setFillPoints(true);
		int [] n = this.dameAleatorios();
		render.setColor(Color.argb(255,n[1],n[2],n[3]));
		
		render2.setChartValuesTextSize(15);
		render2.setLineWidth(5);
		render2.setChartValuesSpacing(10);
		render2.setDisplayChartValues(true);
		render2.setPointStyle(PointStyle.SQUARE);
		render2.setFillPoints(true);
		n = this.dameAleatorios();
		render2.setColor(Color.argb(255,n[1],n[2],n[3]));
		
		//##################################################
		//MODIFICA TODO EL CHART
		mRender.addSeriesRenderer(render);
		mRender.addSeriesRenderer(render2);
		
		mRender.setBarSpacing(1);
		
		//Titulo del reportes
		mRender.setChartTitle("Reporte de Ventas");
		mRender.setFitLegend(true);
		mRender.setChartTitleTextSize(30);
		mRender.setLabelsColor(Color.WHITE); //Esto es para todos los labels

		//Cuadricula
		mRender.setShowGrid(true);
		mRender.setGridColor(Color.WHITE);
		mRender.setXLabels(10); //Cantidad de lineas
		mRender.setYLabels(10); //Cantidad de lineas
		
		//Ejes X,Y
		mRender.setPanEnabled(true,true); //Habilitar movimiento {x,y}
		
		//Cuadrar la grafica
		mRender.setMargins(new int[] {5, 50, 5, 200}); //{derecha, arriba, izquierda, abajo}
		
		//Leyenda de la grafica
		mRender.setLegendTextSize(25);
		mRender.setLegendHeight(70);
		
		mRender.setZoomRate(1.1f);
		mRender.setZoomButtonsVisible(true);
		
		//Centrar las barras
		mRender.setXAxisMin(0);
		mRender.setYAxisMin(0);
		mRender.setXAxisMax(10+1);
		mRender.setYAxisMax(18+1);
		
		mRender.setXTitle("EJE X");
		mRender.setYTitle("EJE Y");
		mRender.setAxisTitleTextSize(25);
		
		Intent intent = ChartFactory.getLineChartIntent(context, dataset, mRender,"Grafica");
		
		return intent;
	}
	
	public int[] dameAleatorios(){
		int [] numeros = new int[4];
		
		for (int i=0;i<4;i++)
			numeros[i] = (int)(Math.random()*255);
		
		return numeros;
	}
}